#!/bin/bash

create_directory() {
    local path=$1
    # 使用[ -d ]来检查目录是否存在
    if [ ! -d "$path" ]; then
        # 如果目录不存在，则使用mkdir命令创建它
        mkdir -p "$path"
        
        # 检查mkdir命令是否成功执行
        if [ $? -eq 0 ]; then
            echo "目录已创建: $path"
        else
            echo "创建目录失败: $path"
        fi
    else
        echo "目录已存在: $path"
    fi
}


echo '创建目录和修改权限'
echo '-------------------'

docker_directory=$HOME/docker_data
create_directory $docker_directory

create_directory "$docker_directory/app"
create_directory "$docker_directory/app/admin"
create_directory "$docker_directory/app/admin/log"

create_directory "$docker_directory/mysql"
create_directory "$docker_directory/mysql/log"
create_directory "$docker_directory/mysql/data"
create_directory "$docker_directory/mysql/conf"
create_directory "$docker_directory/mysql/conf/conf.d"
create_directory "$docker_directory/mysql/conf/mysql.conf.d"

create_directory "$docker_directory/redis"
create_directory "$docker_directory/redis/data"

create_directory "$docker_directory/nginx"
create_directory "$docker_directory/nginx/html"
create_directory "$docker_directory/nginx/logs"
# create_directory "$docker_directory/nginx/conf"

create_directory "$docker_directory/rabbitmq"
create_directory "$docker_directory/rabbitmq/data"

create_directory "$docker_directory/elasticsearch"
create_directory "$docker_directory/elasticsearch/plugins"
create_directory "$docker_directory/elasticsearch/data"
echo "修改权限 $docker_directory/elasticsearch/data/"
chmod 777 "$docker_directory/elasticsearch/data/"

create_directory "$docker_directory/logstash"

create_directory "$docker_directory/mongo"
create_directory "$docker_directory/mongo/db"

create_directory "$docker_directory/minio"
create_directory "$docker_directory/minio/data"

echo '-------------------'










